function [] = fig_sec12_8_ospfWeightACO()

close all;

fileRoot = 'data/ospfWeghtOptimization_aco';

faltorImportancePheromones = 1;
numAnts = 10; 
rhoValues = 0.5;%[0.1 0.2 0.3 0.4];
W=3;

for rho = rhoValues
    baseFileName = [fileRoot '_a' num2str(numAnts) '_rho' num2str(rho*100) '_g' num2str(100*faltorImportancePheromones)];
    congestion = load ([baseFileName '_objFunc.txt']); 
    pheromones_ew = load ([baseFileName '_pheromones_ew.txt']); 

    values_p_tew = pheromones_ew (:,2:end);
    
    avgEntropy = zeros (1,0);
    for t=1:size(values_p_tew,1)
        values_ew(:,:) = values_p_tew(t,:);
        avgEntropy(end+1) = computeEntropy (values_ew , W);
    end
    
    minCong = min (min(congestion(:,2:end)));
    multiplot ('ACO iteration' ,'Entropy' , [1:numel(avgEntropy) ; avgEntropy]' , [] , [] , '-','Pheromones ew' , pheromones_ew, [] , [] , '-' , 'Congestion' , congestion , [] , [0 1.5] , 'x');

end
end

function entr = computeEntropy (v , W)
    numDecisions = numel(v) / W;
    v_wd = reshape (v , [W,numDecisions]);
    v_wd = v_wd * diag(1./sum(v_wd,1)); 
    entropyCoefs = zeros (W,numDecisions);
    nonZeroCoefs = find(v_wd > 0);
    entropyCoefs(nonZeroCoefs) = v_wd(nonZeroCoefs).*log2(v_wd(nonZeroCoefs));
    entr_d = -sum(entropyCoefs,1);
    entr = mean(entr_d); % mean of each column
    if (entr > log2(W)), v_wd , entr_d , error ('Bad'); end
end
